{% extends 'myadmin/base.html' %}
{% block title %}
<title>Book-shop会员管理</title>
{% endblock %}

{% block con %}
<section class="wrapper">
    <!--overview start-->
    <div class="row">
        <div class="col-lg-8">
            <h3 class="page-header"><i class="fa fa-users"></i> 会员管理</h3>
        </div>
    </div>

    <section class="panel">
        <header class="panel-heading">
            会员列表
        </header>
        <div class="panel-body">
            <a href="{% url 'myadmin_users_add' %}" class="btn btn-success" data-toggle="modal" href="#myModal">新增</a>
            <a class="btn btn-warning" data-toggle="modal" href="#myModal2">保存</a>

            <div class="btn-group pull-right">
                <input class="form-control" placeholder="搜索" type="text" name="keywords">
            </div>
        </div>
        <table class="table table-striped table-advance table-hover">
            <thead>
            <tr>
                <th> ID</th>
                <th> 头像</th>
                <th> 手机号</th>
                <th> 昵称</th>
                <th> 性别</th>
                <th> 身份</th>
                <th> 注册时间</th>
                <th> 操作</th>
            </tr>
            </thead>
            <tbody>
            {% for i in data %}
            <tr>
                <td>{{ i.id }}</td>
                <td><img src="{{ i.face }}" style="max-width: 50px; min-width: 45px;" class="tpl-table-line-img"></td>
                <td>{{ i.phone }}</td>
                <td>{{ i.nikename }}</td>
                <td>{% if i.sex == '0' %}女{% elif i.sex == '1' %}男{% else %}未知{% endif %}</td>
                <td>{% if i.usertype == 0 %}
                    狼人{% elif i.usertype == 1 %}
                    预言家{% elif i.usertype == 2 %}
                    平民{% else %}
                    未知{% endif %}
                </td>
                <td>{{i.registerdate|date:'Y-m-d h:i:s'}}</td>
                <td>
                    <div class="btn-group">
                        <a class="btn btn-info" href="{% url 'myadmin_users_add' %}">编辑</a>
                        <a class="btn btn-danger"><i class="icoclose_alt">删除</i></a>
                    </div>
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
        <!-- <ul class="pagination"> -->
        <ul class="pagination pull-right">
            {% load pagetag %}
            <!-- 使用自定义分页标签 -->
            {% showpage data.paginator.num_pages request %}
        </ul>
    </section>
</section>
    <script src="/static/myadmin/assets/js/jquery-1.12.4.min.js"></script>
    <script>
      $(".icoclose_alt").click(function(){
        // 获取当前的数据id
        id = $(this).parents('tr').find('td:first').text()
        a = $(this)
        // 发送Ajax请求到后台
        $.get("{% url 'myadmin_users_delete' %}",{'id':id},function(data){
          if (data['code'] == 0){
            a.parents('tr').remove()
          }
          alert(data['msg'])
        },'json')
      });

    </script>
    {% endblock %}